<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="头像">
            <el-input v-model="form.avatarId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="form.email" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.enabled" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.user_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="昵称">
            <el-input v-model="form.nickName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="性别">
            <el-select v-model="form.sex" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.sex_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="微信小程序id">
            <el-input v-model="form.miniOpenId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="微信公众号id">
            <el-input v-model="form.officialOpenId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="微信唯一标识">
            <el-input v-model="form.unionId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所在地">
            <el-input v-model="form.localtion" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户定位">
            <el-select v-model="form.orientation" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.wx_user_role"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="认证资料id">
            <el-input v-model="form.authDataId" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column v-if="columns.visible('avatarId')" prop="avatarId" label="头像" />
        <el-table-column v-if="columns.visible('email')" prop="email" label="邮箱" />
        <el-table-column v-if="columns.visible('enabled')" prop="enabled" label="状态">
          <template slot-scope="scope">
            {{ dict.label.user_status[scope.row.enabled] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('nickName')" prop="nickName" label="昵称" />
        <el-table-column v-if="columns.visible('sex')" prop="sex" label="性别">
          <template slot-scope="scope">
            {{ dict.label.sex_status[scope.row.sex] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('miniOpenId')" prop="miniOpenId" label="微信小程序id" />
        <el-table-column v-if="columns.visible('officialOpenId')" prop="officialOpenId" label="微信公众号id" />
        <el-table-column v-if="columns.visible('unionId')" prop="unionId" label="微信唯一标识" />
        <el-table-column v-if="columns.visible('localtion')" prop="localtion" label="所在地" />
        <el-table-column v-if="columns.visible('orientation')" prop="orientation" label="用户定位">
          <template slot-scope="scope">
            {{ dict.label.wx_user_role[scope.row.orientation] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('authDataId')" prop="authDataId" label="认证资料id" />
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="更新时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','wxUser:edit','wxUser:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWxUser from '@/api/wxUser'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '微信用户', url: 'api/wxUser', sort: 'id,desc', crudMethod: { ...crudWxUser }})
const defaultForm = { id: null, avatarId: null, email: null, enabled: null, nickName: null, sex: null, miniOpenId: null, officialOpenId: null, unionId: null, localtion: null, orientation: null, authDataId: null, createTime: null, updateTime: null }
export default {
  name: 'WxUser',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['user_status', 'sex_status', 'wx_user_role'],
  data() {
    return {
      permission: {
        add: ['admin', 'wxUser:add'],
        edit: ['admin', 'wxUser:edit'],
        del: ['admin', 'wxUser:del']
      },
      rules: {
      }}
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
